from django.db import models

class Essential(models.Model):
    id_num = models.AutoField(primary_key=True, verbose_name='序号')
    id = models.CharField(max_length=255, blank=True, null=True, db_index=True, verbose_name='企业ID')
    firm_name = models.CharField(max_length=255, blank=True, null=True, db_index=True, verbose_name='企业名称')
    usc_code = models.CharField(max_length=255, blank=True, null=True, verbose_name='社会信用码')
    firm_category = models.CharField(max_length=255, blank=True, null=True, verbose_name='企业类型')
    legal_rep = models.CharField(max_length=255, blank=True, null=True, verbose_name='法人代表')
    legal_rep_type = models.CharField(max_length=255, blank=True, null=True, verbose_name='法人代表类型')
    est_date = models.DateField(blank=True, null=True, verbose_name='成立日期')
    gd_longitude = models.FloatField(blank=True, null=True, verbose_name='经度')
    gd_latitude = models.FloatField(blank=True, null=True, verbose_name='纬度')

    class Meta:
        ordering = ['-id_num']  # 按 id_num 降序排序
        verbose_name = '企业基本信息'
        verbose_name_plural = '企业基本信息'


    def __str__(self):
        return self.firm_name or ''


class BASIS(models.Model):
    id_num = models.AutoField(primary_key=True)
    id = models.CharField(max_length=64, blank=True, null=True, db_index=True, verbose_name='企业ID')
    name = models.CharField(max_length=64, blank=True, null=True, db_index=True, verbose_name='企业名称')
    cai_1 = models.IntegerField(blank=True, null=True, verbose_name='近1年被裁判次数')
    cai_2 = models.IntegerField(blank=True, null=True, verbose_name='近2年被裁判次数')
    cai_3 = models.IntegerField(blank=True, null=True, verbose_name='近3年被裁判次数')
    s_an_1 = models.FloatField(blank=True, null=True, verbose_name='近1年涉案金额')
    s_an_2 = models.FloatField(blank=True, null=True, verbose_name='近2年涉案金额')
    s_an_3 = models.FloatField(blank=True, null=True, verbose_name='近3年涉案金额')
    li_an_1 = models.IntegerField(blank=True, null=True, verbose_name='近1年立案次数')
    li_an_2 = models.IntegerField(blank=True, null=True, verbose_name='近2年立案次数')
    li_an_3 = models.IntegerField(blank=True, null=True, verbose_name='近3年立案次数')
    zhi_1 = models.IntegerField(blank=True, null=True, verbose_name='近1年被执行次数')
    zhi_2 = models.IntegerField(blank=True, null=True, verbose_name='近2年被执行次数')
    zhi_3 = models.IntegerField(blank=True, null=True, verbose_name='近3年被执行次数')
    f_ren = models.CharField(max_length=128, blank=True, null=True, verbose_name='法人')
    zhuce_money = models.CharField(max_length=64, blank=True, null=True, verbose_name='注册资本')
    jing_fan = models.TextField(blank=True, null=True, verbose_name='经营范围') 
    qiye_type = models.CharField(max_length=64, blank=True, null=True, verbose_name='企业类型')

    class Meta:
        ordering = ['-id_num']  # 按 id_num 降序排序
        verbose_name = '企业基准风险信息'
        verbose_name_plural = '企业基准风险信息'

    def __str__(self):
        return self.name or ''
